/**
 * Accenture - Servicing Front-end
 */
package sk.lukaskrupa.guess.the.color.core;

import sk.lukaskrupa.guess.the.color.ui.R;

/**
 * Close list of all possible difficulties.
 * 
 * @author Lukas Krupa (lukas0krupa@gmail.com)
 * 
 */
public enum DifficultyEnum {

	VERY_EASY(0, R.id.veryeasy, 6), EASY(1, R.id.easy, 6), MEDIUM(2, R.id.medium, 8), HARD(3, R.id.hard, 8);

	private int value;
	private int radioButtonId;
	private int numberOfColors;

	/**
	 * Contructs Enum.
	 * 
	 * @param value
	 *            internal representation
	 * @param radioButtonId
	 *            according to application resources
	 */
	private DifficultyEnum(int value, int radioButtonId, int numberOfColors) {
		this.value = value;
		this.radioButtonId = radioButtonId;
		this.numberOfColors = numberOfColors;
	}

	/**
	 * Returns DiffictultyEnum ResourceId for given internal value.
	 * 
	 * @param value
	 *            that we need ResourceId for
	 * @return DifficultyEnum
	 */
	public static int getResourceIdForInternalValue(int value) {
		for (DifficultyEnum singleEnum : DifficultyEnum.values()) {
			if (singleEnum.getValue() == value) {
				return singleEnum.getRadioButtonId();
			}
		}

		throw new IllegalStateException("This state should occur. There should be enum for radio button that is selected.");

	}
	/**
	 * Returns DiffictultyEnum for given resource ID.
	 * 
	 * @param radioButtonId
	 *            that is checked
	 * @return DifficultyEnum
	 */
	public static DifficultyEnum enumForResourceId(int radioButtonId) {
		for (DifficultyEnum singleEnum : DifficultyEnum.values()) {
			if (singleEnum.getRadioButtonId() == radioButtonId) {
				return singleEnum;
			}
		}

		throw new IllegalStateException("This state should occur. There should be enum for radio button that is selected.");
	}

	/**
	 * Returns DiffictultyEnum for given internal representation.
	 * 
	 * @param value
	 *            that enum should have
	 * @return DifficultyEnum
	 */
	public static DifficultyEnum enumForValue(int value) {
		for (DifficultyEnum singleEnum : DifficultyEnum.values()) {
			if (singleEnum.getValue() == value) {
				return singleEnum;
			}
		}

		throw new IllegalStateException("This state should occur. There should be enum with value from app settings file.");
	}

	/**
	 * Gets value.
	 * 
	 * @return the value
	 */
	public int getValue() {
		return this.value;
	}

	/**
	 * Gets application radio button ID.
	 * 
	 * @return ID according to R.id.radioButtonXXX
	 */
	public int getRadioButtonId() {
		return this.radioButtonId;
	}

	/**
	 * Gets numberOfColors.
	 * 
	 * @return the numberOfColors
	 */
	public int getNumberOfColors() {
		return this.numberOfColors;
	}
}
